package com.yly.plugindemo;

import android.app.Application;
import android.content.res.AssetManager;
import android.util.Log;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import okio.BufferedSource;
import okio.Okio;
import okio.Source;

/**
 * 文件名: BaseApplication.java
 * 描述: 复制资源文件
 * 修改人: [zhengge]
 * 修改日期: 2018-12-07
 * 修改内容: 新增
 */
public class BaseApplication extends Application {
	private static final String TAG ="BaseApplication";
	@Override
	public void onCreate() {
		super.onCreate();
		AssetManager assets = getAssets();
		try {
			InputStream plugin1 = assets.open("Plugin1.apk");
			InputStream plugin2 = assets.open("Plugin2.apk");

			BufferedSource bufferedSource = Okio.buffer(Okio.source(plugin1));
			bufferedSource.readAll(Okio.sink(new File(getFilesDir(),"plugin1")));

			bufferedSource = Okio.buffer(Okio.source(plugin2));
			bufferedSource.readAll(Okio.sink(new File(getFilesDir(),"plugin2")));
			Log.d(TAG, "onCreate: move finished.");

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
